﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using nwrole.plugin;

namespace nwrole.testplugin {
    [Export(typeof(IPlugin))]
    public class TestPluginB : IPlugin {
        
        [NwroleConfig("OtherValue")]
        public string OtherValue { get; set; }

        protected IPluginDebug debug;

        private AutoResetEvent waitEvent = new AutoResetEvent(false);

        private bool running;

        public TestPluginB() {
            OtherValue = "Något annat";
        }

        public void Start(IPluginDebug debug) {
            this.debug = debug;

            running = true;

            Trace.TraceInformation("TestPluginB.Start()");

            debug.Log(LogLevel.Info, "Hello from TestPluginB", null);

            while (running)
            {
                //debug.Pulse("idle");

                waitEvent.WaitOne(5000);
            }
        }

        public void Stop() {
            Trace.TraceInformation("TestPluginB.Stop()");

            running = false;
            waitEvent.Set();
        } 

        public void ConfigurationChanged() {
            Trace.TraceInformation("TestPluginB.ConfigurationChanged()");
        }
    }
}
